package gui;



import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.Text;

public class GuiLayout {
	private Display display;
	private Shell shell;
	private final int BALANCE_PAID_WIDTH = 100;
	
	private Label lblBeginningBalance;
	private Text txtBeginningBalance;
	
	private Label lblTotalPaid;
	private Text txtTotalPaid;
	
	private Label lblRemainingBalance;
	private Text txtRemainingBalance;
	
	private Label lblVerticalSeparator;
	
	private Text txtPaymentDisplay;
	
	private Label lblMonth;
	private Text txtMonth;
	
	private Label lblDay;
	private Text txtDay;
	
	private Label lblYear;
	private Text txtYear;
	
	private Label lblAmount;
	private Text txtAmount;
	
	private Button btnAddPayment;
	
	private Label lblIndex;
	private Text txtIndex;
	private Button btnRemoveRecord;
	
	public GuiLayout(Display display){
		this.display = display;
		createContents();
		
	}
	
	private void createContents(){
		Shell shell = new Shell();
		shell.setLayout(new FormLayout());
		FormData data = new FormData();
		
		//Beginning Balance
		this.lblBeginningBalance = new Label(shell, SWT.NONE);
		this.lblBeginningBalance.setText("Beginning Balance: ");
		data.left = new FormAttachment(0, 20);
		data.top = new FormAttachment(0, 20);
		this.lblBeginningBalance.setLayoutData(data);
		
		this.txtBeginningBalance = new Text(shell, SWT.SINGLE | SWT.READ_ONLY | SWT.BORDER);
		this.txtBeginningBalance.setText("text Added Later");
		data = new FormData();
		data.left = new FormAttachment(this.lblBeginningBalance, 10);
		data.bottom = new FormAttachment(this.lblBeginningBalance,0,SWT.BOTTOM);
		data.width = this.BALANCE_PAID_WIDTH;
		this.txtBeginningBalance.setLayoutData(data);
		
		
		/*
		 * TOTAL PAID
		 * */
		this.lblTotalPaid = new Label(shell, SWT.NONE);
		this.lblTotalPaid.setText("Total Paid:");
		data = new FormData();
		data.top = new FormAttachment(lblBeginningBalance, 10);
		data.left = new FormAttachment(lblBeginningBalance, 0, SWT.LEFT);
		this.lblTotalPaid.setLayoutData(data);
		
		this.txtTotalPaid = new Text(shell, SWT.SINGLE | SWT.READ_ONLY | SWT.BORDER);
		this.txtTotalPaid.setText("Text to come");
		data = new FormData();
		data.left = new FormAttachment(this.txtBeginningBalance, 0, SWT.LEFT);
		data.bottom = new FormAttachment(this.lblTotalPaid, 0, SWT.BOTTOM);
		data.width = this.BALANCE_PAID_WIDTH;
		this.txtTotalPaid.setLayoutData(data);
		
		/*
		 * Remaining Balance
		 * */
		this.lblRemainingBalance = new Label(shell, SWT.NONE);
		this.lblRemainingBalance.setText("Remaining Balance:");
		data = new FormData();
		data.top = new FormAttachment(lblTotalPaid, 10);
		data.left = new FormAttachment(this.lblTotalPaid, 0, SWT.LEFT);
		this.lblRemainingBalance.setLayoutData(data);
		
		this.txtRemainingBalance = new Text(shell, SWT.SINGLE | SWT.READ_ONLY | SWT.BORDER);
		this.txtRemainingBalance.setText("coming soon");
		data = new FormData();
		data.left = new FormAttachment(this.txtBeginningBalance, 0, SWT.LEFT);
		data.bottom = new FormAttachment(this.lblRemainingBalance, 0, SWT.BOTTOM);
		data.width = this.BALANCE_PAID_WIDTH;
		this.txtRemainingBalance.setLayoutData(data);
		
		/*
		 * Payment Display Table
		 * */
		this.txtPaymentDisplay = new Text(shell, SWT.MULTI | SWT.READ_ONLY | SWT.BORDER | SWT.V_SCROLL);
		data = new FormData();
		data.right = new FormAttachment(this.txtBeginningBalance, 0, SWT.RIGHT);
		data.left = new FormAttachment(this.lblBeginningBalance, 0, SWT.LEFT);
		data.top = new FormAttachment(lblRemainingBalance, 50);
		data.bottom = new FormAttachment(100, -10);
		data.height = 100;
		this.txtPaymentDisplay.setLayoutData(data);
		
		
		/*
		 * Vertical Separator
		 * */
		this.lblVerticalSeparator = new Label(shell, SWT.SEPARATOR);
		data = new FormData();
		data.top = new FormAttachment(0,0);
		data.left = new FormAttachment(this.txtBeginningBalance, 20);
		data.bottom = new FormAttachment(100, 0);
		this.lblVerticalSeparator.setLayoutData(data);
		
		/*
		 * Right side of the Screen
		 * 
		 * Inserting a new payment
		 * */
		this.lblMonth = new Label(shell, SWT.NONE);
		this.lblMonth.setText("Month:");
		data = new FormData();
		data.left = new FormAttachment(this.lblVerticalSeparator, 20);
		this.lblMonth.setLayoutData(data);
		
		this.txtMonth = new Text(shell, SWT.SINGLE | SWT.BORDER);
		data = new FormData();
		data.left = new FormAttachment(this.lblMonth, 0, SWT.LEFT);
		data.top = new FormAttachment(this.lblMonth, 10, SWT.BOTTOM);
		data.width = 20;
		this.txtMonth.setLayoutData(data);
		
		////////
		this.lblDay = new Label(shell, SWT.NONE);
		this.lblDay.setText("Day:");
		data = new FormData();
		data.left = new FormAttachment(this.lblMonth, 30, SWT.RIGHT);
		this.lblDay.setLayoutData(data);
		
		this.txtDay = new Text(shell, SWT.SINGLE | SWT.BORDER);
		data = new FormData();
		data.left = new FormAttachment(this.lblDay, 0, SWT.LEFT);
		data.top = new FormAttachment(this.lblDay, 10, SWT.BOTTOM);
		data.width = 20;
		this.txtDay.setLayoutData(data);
		
		////////
		this.lblYear = new Label(shell, SWT.NONE);
		this.lblYear.setText("Year:");
		data = new FormData();
		data.left = new FormAttachment(this.lblDay, 30, SWT.RIGHT);
		data.right = new FormAttachment(100, -20);
		this.lblYear.setLayoutData(data);
		
		this.txtYear = new Text(shell, SWT.SINGLE | SWT.BORDER);
		data = new FormData();
		data.left = new FormAttachment(this.lblYear, 0, SWT.LEFT);
		data.top = new FormAttachment(this.lblYear, 10, SWT.BOTTOM);
		data.width = 25;
		this.txtYear.setLayoutData(data);
		
		//Amount
		this.lblAmount = new Label(shell, SWT.NONE);
		this.lblAmount.setText("Amount:");
		data = new FormData();
		data.left = new FormAttachment(this.lblMonth, 0, SWT.LEFT);
		data.top = new FormAttachment(this.lblMonth, 50, SWT.BOTTOM);
		this.lblAmount.setLayoutData(data);
		
		this.txtAmount = new Text(shell,SWT.SINGLE | SWT.BORDER );
		data = new FormData();
		data.left = new FormAttachment(this.lblAmount, 0, SWT.LEFT);
		data.top = new FormAttachment(this.lblAmount, 10, SWT.BOTTOM);
		data.right = new FormAttachment(this.txtYear, 0, SWT.RIGHT);
		this.txtAmount.setLayoutData(data);
		
		//Add Payment Button
		this.btnAddPayment = new Button(shell, SWT.PUSH);
		this.btnAddPayment.setText("Add Payment");
		data = new FormData();
		data.left = new FormAttachment(this.txtAmount, 0, SWT.LEFT);
		data.top = new FormAttachment(this.txtAmount, 10, SWT.BOTTOM);
		data.right = new FormAttachment(this.txtAmount, 0, SWT.RIGHT);
		this.btnAddPayment.setLayoutData(data);
		
		/*
		 * Remove Record Option
		 * */
		this.lblIndex = new Label(shell, SWT.NONE);
		this.lblIndex.setText("Index:");
		data = new FormData();
		data.left = new FormAttachment(this.lblMonth, 0, SWT.LEFT);
		data.top = new FormAttachment(this.btnAddPayment, 50, SWT.BOTTOM);
		this.lblIndex.setLayoutData(data);
		
		this.txtIndex = new Text(shell, SWT.SINGLE | SWT.BORDER);
		data = new FormData();
		data.left = new FormAttachment(this.lblIndex, 10, SWT.RIGHT);
		data.bottom = new FormAttachment(this.lblIndex, 0, SWT.BOTTOM);
		this.txtIndex.setLayoutData(data);
		
		this.btnRemoveRecord = new Button(shell, SWT.PUSH);
		this.btnRemoveRecord.setText("Remove Record");
		data = new FormData();
		data.left = new FormAttachment(this.lblIndex, 0, SWT.LEFT);
		data.right = new FormAttachment(this.txtIndex, 0, SWT.RIGHT);
		data.top = new FormAttachment(this.lblIndex, 10, SWT.BOTTOM);
		this.btnRemoveRecord.setLayoutData(data);
		
		//last thing to do
		shell.pack();
		shell.setText("Joe's Car Repayment Calculator");
		this.shell = shell;
	}
	
public Shell getShell(){
		return this.shell;
	}

	public Button getBtnAddPayment() {
		return btnAddPayment;
	}

	public Text getTxtBeginningBalance() {
		return txtBeginningBalance;
	}

	public Text getTxtTotalPaid() {
		return txtTotalPaid;
	}

	public Text getTxtRemainingBalance() {
		return txtRemainingBalance;
	}

	public Text getTxtPaymentDisplay() {
		return txtPaymentDisplay;
	}

	public Text getTxtDay() {
		return txtDay;
	}

	public Text getTxtMonth() {
		return txtMonth;
	}

	public Text getTxtYear() {
		return txtYear;
	}

	public Text getTxtAmount() {
		return txtAmount;
	}

	public Text getTxtIndex() {
		return txtIndex;
	}

	public Button getBtnRemoveRecord() {
		return btnRemoveRecord;
	}
	
	

}
